#include "widget.h"
#include "ui_widget.h"

#include <QByteArray>
#include <QPixmap>
#include <QTimer>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    qnam = new QNetworkAccessManager(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString urlstr = ui->lineEdit->text();
//    QUrl url(urlstr);

    QNetworkRequest req{QUrl(urlstr)};

    qnam->get(req);

    connect(qnam, SIGNAL(finished(QNetworkReply *)), this, SLOT(recvhttp(QNetworkReply *)));
}

void Widget::recvhttp(QNetworkReply *re)
{
    QByteArray buf = re->readAll();
    QPixmap pix;
    pix.loadFromData(buf);
    pix.scaled(ui->lineEdit->size(), Qt::KeepAspectRatio);
    ui->label->setPixmap(pix);
}

